<?php

class searchResultsComponents extends sfComponents
{
  public function executeRender()
  {
      $request = sfContext::getInstance()->getRequest();
      $limit   = $request->hasParameter('limit') ? $request->getParameter('limit') : 0;
      
      //if($request->getParameter('body'))
      //{
          $productModel = new Product();
          $doctrine     = $productModel->searchProducts($this->getUser(), $request->getParameter('body'));
          
          // Highlight keyword
          $this->products = array();
          $this->links    = array();
          
          foreach($doctrine as $j => $product)
          {
              $this->products[$j] = $product;
              $this->products[$j]['Translation'][$this->getUser()->getCulture()]['name'] = preg_replace(
                  '/('.preg_quote($request->getParameter('body')).')/is', 
                  '<span style="background: yellow">$1</span>', 
                  $this->products[$j]['Translation'][$this->getUser()->getCulture()]['name']
              );
          }
          
          $this->links = LinkGen::getInstance(LinkGen::PRODUCT)->collectionLinks($this->products);
      //}
  }
};